

#include "task_send_command.h"
#include "comm_utils.h"

SendCommandTask::SendCommandTask(EvSerial *serial, int cmd_id, const QByteArray &send_data)
    : TaskCommBase(serial), send_data_(send_data)
{
    cmd_id_ = cmd_id;
}

void SendCommandTask::run()
{
    QString mssg = QString("请求自定义命令...");
    emit messageLogged(LogUtils::makeLogBin(mssg));

    int ret = callSendCommand(cmd_id_, send_data_);
    if (ret != 0) {
        mssg = QString("请求自定义命令失败, 错误码: %1").arg(ret);
        emit messageLogged(LogUtils::makeLogBin(mssg));
        emit finished(false);
    } else {
        emit messageLogged(LogUtils::makeLogBin("请求自定义命令成功"));
        emit finished(true);
    }
}
